import { Table,Switch,Image } from 'antd'
import React, { useEffect, useState } from 'react'

import {getShowData} from '../../api/pro'

const Recommend = () => {

  const [proList, setProList] = useState()

  useEffect(()=>{
    getShowData({
      type: 'isrecommend',
      flag: 1
    }).then(res => {
      // console.log(res);
      setProList(res.data)
    })
  }, [])

  const [current,setCurrent] = useState(1)
  const columns = [
    {
      title: '序号',
      render(t,r,i){
        return <span>{(current - 1) * 10 + i + 1}</span>
      }
    },
    {
      title: '商品名称',
      dataIndex: 'proname',
      width: 350
    },
    {
      title: '商品图片',
      dataIndex: 'img1',
      render(t){
        return <Image src={t} height={50} />
      }
    },{
      title: '商品分类',
      dataIndex: 'category'
    },{
      title: '商品价格',
      dataIndex: 'originprice'
    },{
      title: '商品折扣',
      dataIndex: 'discount'
    },{
      title: '是否推荐',
      dataIndex: 'isrecommend',
      render(t){
        return <Switch defaultChecked={t} />
      }
    },{
      title: '是否售卖',
      dataIndex: 'issale',
      render(t){
        return <Switch defaultChecked={t} />
      }
    },{
      title: '是否秒杀',
      dataIndex: 'isseckill',
      render(t){
        return <Switch defaultChecked={t} />
      }
    }
  ]

  return (
    <div>
      <h1>推荐列表</h1>
      <Table 
      dataSource={proList} 
      rowKey={'proid'}
      columns={columns}
      pagination={{
        current,
        onChange(count){
          setCurrent(count)
        }
      }}
      scroll={{
        y: 500,
        x: 1500
      }}
       />
    </div>
  )
}

export default Recommend